/**
 * Created by taohj on 2014/8/14.
 */


var dataset_ = new Object();


/**
 * 模块列表
 * */
dataset_.initgrid = function () {

    dataset_.datagrid = $("#admin_dataset_list_datagrid");
    dataset_.datagrid.datagrid({
        url: '/admin/dataset/list',
        singleSelect: true,
        collapsible: true,
        pagination: true,
        rownumbers: true,
        fitColumns: true,
        sortName: "id",
        sortOrder: "asc",
        fit: true,
        pageList: [20, 50, 100],
        pageSize: 20,
        toolbar: [
            {
                iconCls: 'icon-add',
                text: '新增',
                handler: function () {
                    var createDialog = $("<div></div>");
                    createDialog.dialog({
                        title: '新增',
                        href: '/admin/dataset/createV',
                        modal: true,
                        width: 400,
                        top:200
                    });


                }
            },
            '-',
            {
                iconCls: 'icon-edit',
                text: '更新',
                handler: function () {
                    var selectRow = dataset_.datagrid.datagrid("getSelected");
                    if (!selectRow) {

                        return;
                    }
                    var id = "";
                    if (selectRow) {
                        id = selectRow.id;
                    }

                    var modifyDialog = $("<div></div>");
                    modifyDialog.dialog({
                        title: '更新',
                        href: '/admin/dataset/modifyV' + '?id=' + id,
                        modal: true,
                        width: 400,
                        top:200
                    });

                }
            },
            '-',
            {
                iconCls: 'icon-remove',
                text: '删除',
                handler: function () {

                    var selectRow = dataset_.datagrid.datagrid("getSelected");
                    if (!selectRow) {

                        return;
                    }

                    $.messager.confirm('删除确认', '确定要删除此项么？ ', function (r) {
                        if (r) {
                            $.post('/admin/dataset/remove', {
                                id: selectRow.id
                            }, function (result) {
                                util.requestUtil(result, null, dataset_.datagrid);
                            });
                        }
                    });
                    console.info(selectRow);
                }
            }
        ],
        columns: [
            [
                {field: "id", title: "编号", width: 40, sortable: true},
                {field: "name", title: "名称", width: 100, sortable: true},
                {field: "org", title: "机构", width: 100, sortable: true, formatter: function (value) {
                    return value ? value.name : '';
                }},
                {field: "theme", title: "主题", width: 100, sortable: true, formatter: function (value) {
                    return value ? value.name : '';
                }
                },
                {field: "description", title: "简介", width: 100},
                {field: "inTime", title: "加入时间", width: 100},
                {field: "status", title: "状态", width: 100, formatter: function (value) {
                    return value ? value.name : '';
                }},
                {field: "creater", title: "创建人", width: 100, formatter: function (value) {
                    return value ? value.username : '';
                }},
                {field: "createTime", title: "创建时间", width: 100}

            ]
        ]
    });

};


//新建提交
dataset_.createSubmit = function (button) {
    alert(1);
    var form = util.form(button);
    form.form('submit', {
        url: '/admin/dataset/create',
        success: function (result) {
            var dialog = $(button).closest("div.window-body");
            util.requestUtil(result, dialog, dataset_.datagrid)
        }
    });
};





//修改提交
dataset_.modifySubmit = function (button) {
    var form = util.form(button);
    form.form('submit', {
        url: '/admin/dataset/modify',
        success: function (result) {
            var dialog = $(button).closest("div.window-body");
            util.requestUtil(result, dialog, dataset_.datagrid)
        }
    });
};


//搜索
dataset_.searchSubmit = function (button) {
    var form = util.form(button);
    var params = util.serializeObject(form);
    dataset_.datagrid.datagrid("load", params);
};

